package com.sun.config;

import com.sun.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//扩展SpringMvc
@Configuration
public class MvcConfig implements WebMvcConfigurer {

	//扩展视图控制器 映射器
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		//浏览器发送/welcome请求 到达welcome页面

		registry.addViewController("/index").setViewName("login");
		/*registry.addViewController("/main").setViewName("main");*/
		/*访问路径"/toAddUser"时 到达userAdd页面*/
		/*registry.addViewController("/toAddUser").setViewName("userAdd");*/
	}

	// 激活拦截器-登录拦截
	@Override
	public void addInterceptors(InterceptorRegistry registry){
		registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/*")
				.excludePathPatterns("/toLogin","/index","/toRegister","/register","/login","/batchDelete","/uploads/**");
	}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
	registry.addResourceHandler("/uploads/avatars/**")
			.addResourceLocations("file:D:/experiment/javaEE/sbMybatis/uploads/avatars/");
}
}